sz = gbfread(ibuf, 1, 52, file_in);
if ((sz < 52) ||
- strncmp(ibuf, ezsig, sizeof(ezsig)-1) ||
+ strncmp(ibuf, ezsig, strlen(ezsig)) ||
(ibuf[51] != 'W')) {
fatal(MYNAME ": %s is not an EasyGPS file.\n", qPrintable(fname));
}
#include "inifile.h"
#include <QtCore/QXmlStreamWriter>
+#include <cassert>
#include <cstdio>
#include <cstdlib>
char* c;
char key[3];
+ // use assertion to silence gcc 7.3 warning
+ // warning: ‘%d’ directive output may be truncated writing between 1 and 11 bytes into a region of size 3 [-Wformat-truncation=]
+ assert((i>=0) && (i<16));
snprintf(key, sizeof(key), "%d", i + 1);
c = inifile_readstr(global_opts.inifile, GMSD_SECTION_CATEGORIES, key);
if ((c != nullptr) && (case_ignore_strcmp(c, category_name) == 0)) {
#include "defs.h"
#include "csv_util.h"
#include <QtCore/QHash>
+//#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
jtr_trkpt_disp_cb(const Waypoint* wpt)
{
char* str, *tmp;
- char stime[10], sdate[7], scourse[6], sspeed[8];
- struct tm tm;
+ char scourse[6], sspeed[8];
+ QString sdate;
+ QString stime;
if (wpt->creation_time.isValid()) {
- const time_t tt = wpt->GetCreationTime().toTime_t();
- tm = *gmtime(&tt);
-
- tm.tm_year += 1900;
- tm.tm_mon += 1;
- snprintf(sdate, sizeof(sdate), "%02d%02d%02d", tm.tm_mday, tm.tm_mon, tm.tm_year % 100);
- snprintf(stime, sizeof(stime), "%02d%02d%02d.%02d", tm.tm_hour, tm.tm_min, tm.tm_sec, wpt->creation_time.time().msec());
- if (wpt->creation_time.time().msec() == 0) {
- stime[6] = 0;
- }
- } else {
- stime[0] = 0;
- sdate[0] = 0;
+ gpsbabel::DateTime dt = wpt->GetCreationTime().toUTC();
+
+ // round time to centiseconds.
+ int msec = dt.time().msec();
+ int csec = lround(msec/10.0);
+ dt = dt.addMSecs(csec*10-msec);
+ sdate = dt.toString(QStringLiteral("ddMMyy"));
+ stime = dt.toString(QStringLiteral("HHmmss.zzz"));
+ // toss milliseconds position which should now be zero.
+ //assert(stime.endsWith('0'));
+ stime.chop(1);
+ // suppress fractional seconds if they are zero.
+ stime = stime.replace(QLatin1String(".00"), QLatin1String(""));
}
if (WAYPT_HAS(wpt, speed) && (wpt->speed >= 0)) {
snprintf(sspeed, sizeof(sspeed), "%.1f", MPS_TO_KNOTS(wpt->speed));
}
xasprintf(&str, "GEOTAG2,%s,%c,%09.4f,%c,%010.4f,%c,%s,%s,%s,,E,A",
- stime,
+ CSTR(stime),
wpt->creation_time.isValid() ? 'A' : 'V',
fabs(degrees2ddmm(wpt->latitude)),
wpt->latitude < 0 ? 'S' : 'N',
wpt->longitude < 0 ? 'W' : 'E',
sspeed,
scourse,
- sdate);
+ CSTR(sdate));
xasprintf(&tmp, "%s*%02X", str, nmea_cksum(str));
xfree(str);
* MRCB
*/
static void
-mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const int isRouteWpt)
+mps_waypoint_w(gbfile* mps_file, int mps_ver, const Waypoint* wpt, const bool isRouteWpt)
{
int reclen;
int lat, lon;
/* if this waypoint hasn't been written then it is okay to do so */
if (wptfound == nullptr) {
- mps_waypoint_w(mps_file_out, mps_ver_out, wpt, (1==0));
+ mps_waypoint_w(mps_file_out, mps_ver_out, wpt, false);
/* ensure we record in our "private" queue what has been
written so that we don't write it again */
if (wptfound == nullptr) {
/* well, we tried to find: it wasn't written and isn't a real waypoint */
- mps_waypoint_w(mps_file_out, mps_ver_out, wpt, (1==1));
+ mps_waypoint_w(mps_file_out, mps_ver_out, wpt, true);
mps_wpt_q_add(&written_route_wpt_head, wpt);
} else {
- mps_waypoint_w(mps_file_out, mps_ver_out, wpt, (1==0));
+ mps_waypoint_w(mps_file_out, mps_ver_out, wpt, false);
/* Simulated real user waypoint */
mps_wpt_q_add(&written_wpt_head, wpt);
}
wptfound = new Waypoint(*wpt);
xfree(wptfound->shortname);
wptfound->shortname = newName;
- mps_waypoint_w(mps_file_out, mps_ver_out, wptfound, (1==0));
+ mps_waypoint_w(mps_file_out, mps_ver_out, wptfound, false);
mps_wpt_q_add(&written_wpt_head, wpt);
}
} else {
- mps_waypoint_w(mps_file_out, mps_ver_out, wpt, (1==0));
+ mps_waypoint_w(mps_file_out, mps_ver_out, wpt, false);
/* ensure we record in out "private" queue what has been
written so that we don't write it again */
mps_wpt_q_add(&written_wpt_head, wpt);
wpt->SetCreationTime(time);
if RND(3) {
- wpt->creation_time = wpt->creation_time.addMSecs(rand_int(1000) * 1000);
+ wpt->creation_time = wpt->creation_time.addMSecs(rand_int(1000));
}
time += rand_int(10) + 1;
#include "defs.h"
#include "jeeps/gpsmath.h" /* for datum conversions */
#include <QtCore/QScopedArrayPointer> // Wish we could use c++11...
+#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
static void
tpo_write_file_header()
{
+ // this assertion will quiet gcc 7.3 warnings about output_state in the strncmp calls
+ // warning: argument 2 null where non-null expected [-Wnonnull]
+ assert(output_state != nullptr);
+
/* force upper-case state name */
strupper(output_state);
#include <QtCore/QDebug>
#endif
-static QString current_tag;
static xg_tag_mapping* xg_tag_tbl;
static QSet<QString> xg_ignore_taglist;
}
static void
-xml_run_parser(QXmlStreamReader& reader, QString& current_tag)
+xml_run_parser(QXmlStreamReader& reader)
{
xg_callback* cb;
+ QString current_tag;
while (!reader.atEnd()) {
switch (reader.tokenType()) {
void xml_read()
{
gpsbabel::File file(rd_fname);
- QString current_tag;
file.open(QIODevice::ReadOnly);
QXmlStreamReader reader(&file);
- xml_run_parser(reader, current_tag);
+ xml_run_parser(reader);
if (reader.hasError()) {
fatal(MYNAME ":Read error: %s (%s, line %ld, col %ld)\n",
qPrintable(reader.errorString()),
// determine file encoding, falls back to UTF-8 if unspecified.
void xml_readstring(const char* str)
{
- QString current_tag;
-
reader_data.append(str);
QXmlStreamReader reader(reader_data);
- xml_run_parser(reader, current_tag);
+ xml_run_parser(reader);
if (reader.hasError()) {
fatal(MYNAME ":Read error: %s (%s, line %ld, col %ld)\n",
qPrintable(reader.errorString()),
// encoding because the source is already Qt's internal UTF-16.
void xml_readunicode(const QString& str)
{
- QString current_tag;
QXmlStreamReader reader(str);
- xml_run_parser(reader, current_tag);
+ xml_run_parser(reader);
}
/******************************************/